package com.linzhaowei.headhuntingservice.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.linzhaowei.headhuntingservice.JobObjectiveDetail;
import com.linzhaowei.headhuntingservice.R;
import com.linzhaowei.headhuntingservice.bean.JobObjective;

import java.util.List;

public class JobObjectiveAdapter extends RecyclerView.Adapter<JobObjectiveAdapter.ViewHolder>{
    private List<JobObjective> jobObjectiveList;


    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView job_text;
        TextView name;
        TextView job_address;
        TextView job_salary;

        View job_view;


        ViewHolder(View view){
            super(view);
            job_view=view;
            job_text=view.findViewById(R.id.j_o_i_job_name);
            name=view.findViewById(R.id.j_o_i_name);
            job_address=view.findViewById(R.id.j_o_i_address);
            job_salary=view.findViewById(R.id.j_o_i_salary);
        }
    }

    public JobObjectiveAdapter(List<JobObjective> list){

        jobObjectiveList=list;
    }

    @Override
    public JobObjectiveAdapter.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType){
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.job_objective_item,parent,false);
        final JobObjectiveAdapter.ViewHolder holder=new JobObjectiveAdapter.ViewHolder(view);

        holder.job_view.setOnClickListener(v -> {
            int position=holder.getAdapterPosition();
            JobObjective jobObjective=jobObjectiveList.get(position);
            Intent intent=new Intent(view.getContext(), JobObjectiveDetail.class);
            intent.putExtra("job_objective_id",jobObjective.getId());
            view.getContext().startActivity(intent);
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(JobObjectiveAdapter.ViewHolder holder, int position){
        JobObjective jobObjective=jobObjectiveList.get(position);
        holder.job_text.setText(jobObjective.getName());
        holder.name.setText(jobObjective.getApplicant_name());
        holder.job_address.setText(jobObjective.getAddress());
        holder.job_salary.setText(String.valueOf(jobObjective.getSalary()));
    }

    @Override
    public int getItemCount(){
        return jobObjectiveList.size();
    }


}
